var server = "https://sdqn5b.cn:449/";
var serverApp = "https://sdqn5b.cn:448/"
var configPro = {};
configPro.projectName = "https://sdqn5b.cn:449/";
configPro.projectID = 1000;
configPro.server_img_interface = configPro.projectName + "common/upload?project=" + configPro.projectID;
configPro.server_img_interfacefr = configPro.projectName + "common/uploadsWang";
configPro.server_img_view = configPro.projectName + "common/file/";
configPro.logger = "debugger";
function kaifang() {
    alr("功能未开放,敬请期待!");
}
function alr(al) {
    setTimeout(function () {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.msg(al, { zIndex: "99999999" });
        });
    }, 600);
}
function checkJson(e) {
    for (key in e) {
        if (e[key] == null || e[key] == 'undefind' || e[key] == '') {
            return false;
        }
    }
    return true;
}
function alrYN(message, yes, no, xl, type) {
    layui.use('layer', function () {
        var layer = layui.layer;
        layer.open({
            content: message
            , type: type
            , btn: ['是', '否']
            , yes: function (index, layero) {
                new yes();
                layer.closeAll();
            }
            , btn2: function (index, layero) {

                new no();
                layer.closeAll();

            }
            , cancel: function () {

                new xl();
                layer.closeAll();
            }
        });
    });
}
function acquire() {

    this.parameter;

    this.parameterMap = {};

    this.test = function () {

        if (window.location.href.split("?") <= 0) {

            return null;

        } else {

            this.parameter = window.location.href.split("?")[1];

        }

    }

    this.packaging = function () {
        if (!this.parameter) {
            return false;
        }
        for (var i = 0; i < this.parameter.split("&").length; i++) {

            var name = this.parameter.split("&")[i].split("=")[0];

            var val = this.parameter.split("&")[i].split("=")[1];

            this.parameterMap[name] = val;

        }

    }

    this.test();

    this.packaging();

}
function jsonToString(pathMap) {
    var path = "";
    for (var key in pathMap) {
        if (path.length != 0) {
            path = path + "&" + key + "=" + pathMap[key];
        } else {
            path = key + "=" + pathMap[key];
        }
    }
    if (typeof (path) == 'undefined') {
        return "code=" + getCode(8);
    } else {
        return path;
    }
}
function getToken() {
    var token = window.localStorage.getItem('token');
    if (token == null || token == '' || typeof (token) == 'undefined') {
        alr("您的令牌已经过期，请重新登录！");
        setTimeout(function () {
            window.location.href = "index.html";
        }, 1000);
    }
    var ret = playGet("/token", "", "", token);
    if (ret.code != 200) {
        alr("登录失效，请重新登录！");
        setTimeout(function () {
            redirectLogin();
        }, 1500);
    }
    return token;
}
function redirectLogin() {
    window.location.href = "index.html";
}
function playGet(urls, pathMap, queryMap, token) {
    var re = "";
    $.ajax({
        url: configPro.projectName + urls + "?" + jsonToString(pathMap),
        type: "GET",
        contentType: "application/json;charset=utf-8",
        headers: { 'Content-Type': 'application/json', 'token': token },
        data: JSON.stringify(queryMap),
        async: false,
        dataType: "json",
        success: function (as) {
            if (configPro.logger == 'debugger') {
                console.log("=============GET==============");
                console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
                console.log("data:" + JSON.stringify(queryMap));
                console.log("bank:" + JSON.stringify(as));
                console.log("=============END==============");
            }
            if (as.code == 401) {
                redirectLogin();
            }
            re = as;
        },
        error: function (es) {
            console.log("=============GET==============");
            console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
            console.log("data:" + JSON.stringify(queryMap));
            console.log("bank:" + JSON.stringify(es));
            console.log("=============END==============");
            re = es;
        }
    });
    return re;
}
//post请求
function playPost(urls, pathMap, queryMap, token) {
    var re = "";
    $.ajax({
        url: configPro.projectName + urls + "?" + jsonToString(pathMap),
        type: "POST",
        contentType: "application/json;charset=utf-8",
        data: queryMap,
        headers: { 'Content-Type': 'application/json', 'token': token },
        async: false,
        dataType: "json",
        success: function (as) {
            if (configPro.logger == 'debugger') {
                console.log("=============GET==============");
                console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
                console.log("data:" + JSON.stringify(queryMap));
                console.log("bank:" + JSON.stringify(as));
                console.log("=============END==============");
            }
            if (as.code == 401) {
                redirectLogin();
            }
            re = as;
        },
        error: function (es) {
            console.log("=============GET==============");
            console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
            console.log("data:" + JSON.stringify(queryMap));
            console.log("bank:" + JSON.stringify(es));
            console.log("=============END==============");
            re = es;
        }
    });
    return re;
}

function playDelete(urls, pathMap, queryMap, token) {
    var re = "";
    $.ajax({
        url: configPro.projectName + urls + "?" + jsonToString(pathMap),
        type: "DELETE",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(queryMap),
        headers: { 'Content-Type': 'application/json', 'token': token },
        async: false,
        dataType: "json",
        success: function (as) {
            if (configPro.logger == 'debugger') {
                console.log("=============GET==============");
                console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
                console.log("data:" + JSON.stringify(queryMap));
                console.log("bank:" + JSON.stringify(as));
                console.log("=============END==============");
            }
            if (as.code == 401) {
                redirectLogin();
            }
            re = as;
        },
        error: function (es) {
            console.log("=============GET==============");
            console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
            console.log("data:" + JSON.stringify(queryMap));
            console.log("bank:" + JSON.stringify(es));
            console.log("=============END==============");
            re = es;
        }
    });
    return re;
}

function playPut(urls, pathMap, queryMap, token) {
    var re = "";
    $.ajax({
        url: configPro.projectName + urls + "?" + jsonToString(pathMap),
        type: "PUT",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(queryMap),
        headers: { 'Content-Type': 'application/json', 'token': token },
        async: false,
        dataType: "json",
        success: function (as) {
            if (configPro.logger == 'debugger') {
                console.log("=============GET==============");
                console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
                console.log("data:" + JSON.stringify(queryMap));
                console.log("bank:" + JSON.stringify(as));
                console.log("=============END==============");
            }
            if (as.code == 401) {
                redirectLogin();
            }
            re = as;
        },
        error: function (es) {
            console.log("=============GET==============");
            console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
            console.log("data:" + JSON.stringify(queryMap));
            console.log("bank:" + JSON.stringify(es));
            console.log("=============END==============");
            re = es;
        }
    });
    return re;
}

function randomString(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}
